#version 330 core

uniform sampler2D diffuseTexture;
uniform vec3 viewPos;
uniform vec3 lightDirection;
uniform vec4 lightColor;
uniform vec4 ambientColor;

in VsOut
{
	vec3 position;
	vec3 normal;
    vec2 uv;
} vsIn;

out vec4 fragColor;

void main()
{	
	vec3 lightDir = normalize(-lightDirection);
	vec3 normal = normalize(vsIn.normal);
	float diffuse = max(dot(normal, lightDir), 0.0);
    
    vec3 viewDir = normalize(viewPos - vsIn.position);
    vec3 reflectLightDir = reflect(-lightDir, normal);
    float spec = pow(max(dot(reflectLightDir, viewDir), 0), 3);
	
	vec4 diffuseColor = texture(diffuseTexture, vsIn.uv);
	
    fragColor = lightColor * (diffuseColor * ambientColor + diffuseColor * (diffuse + spec));
}
